# Function to combine all "reversal" results, specifying a particular measure of fighting and temporal window
# The temporal splits of "all," "early," and "later" are taken from slabels vector in the Chapter 5 code.
combineResults = function(splits=slabels, fightMeasure, window) {
  
  resultSets = paste("turn", slabels, fightMeasure, window, sep="_")
  
  resultList = list()
  for (j in 1:length(resultSets)) {
    # Get one set of results
    oneSummary = summary(get(resultSets[j]))
  
    # Extract the coefficient estimates and SEs; make 95% CIs
    oneResult = data.frame(est = oneSummary[["coefficients"]][,1],
                         se = oneSummary[["coefficients"]][,2])
    oneResult = oneResult %>% mutate(lower95 = est - 1.96*se,
                                 upper95 = est + 1.96*se) %>%
      mutate(model=slabels[j]) %>% mutate(vars=rownames(oneResult)) %>%
      mutate(fight=fightMeasure)
    
    resultList[[j]] = oneResult
  }
  
  # Put all results together
  resData = bind_rows(resultList)
  
  # Remove unnecessary variables, rearrange necesary ones
  resData = filter(resData, !grepl("warName", vars))
  resData = filter(resData, !grepl("Intercept", vars))
  resData$vars = factor(resData$vars, levels=c("logBattles", "dayNum", "nBattle", "neg", "afterNeg", "post45"))
  
  # Label models and mark statistical significance
  resData$model = factor(resData$model, levels=c("all", "early", "later"))
  resData$signif = ifelse(resData$lower95 > 0 | resData$upper95 < 0, "Yes", "No")
  
  return(resData)
}
